package punctuatedEquilibriumTest;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import punctuatedEquilibrium.Phenotype;
import punctuatedEquilibrium.PhenotypeFactory;
import punctuatedEquilibrium.SetOfPhenotypes;
import punctuatedEquilibrium.Trait;
import punctuatedEquilibrium.TraitFactory;

public class SetOfPhenotypesTest {
	SetOfPhenotypes	phenotypes;

	@Before
	public void setUp() {
		phenotypes = new SetOfPhenotypes();
	}

	@Test
	public void testCreate() {
		assertNotNull(phenotypes);
	}

	@Test
	public void testOnePhenotype() {
		phenotypes.add(PhenotypeFactory.getStandardPhenotype());
		Phenotype average = phenotypes.computeAveragePhenotype();
		assertTrue(average
				.isEquivalent(PhenotypeFactory.getStandardPhenotype()));
	}

	@Test
	public void testTwoPhenotypes() {
		phenotypes.add(PhenotypeFactory.getStandardPhenotype());
		phenotypes.add(PhenotypeFactory.getNullPhenotype());
		Double[] standardTraitValues = TraitFactory.getArrayOfTraitValues();
		Trait[] expectedTraits = new Trait[3];
		for (int i = 0; i < expectedTraits.length; i++) {
			expectedTraits[i] = new Trait(standardTraitValues[i] / 2);
		}
		Phenotype expected = new Phenotype(expectedTraits);
		Phenotype actual = phenotypes.computeAveragePhenotype();
		assertTrue(expected.isEquivalent(actual));
	}
}
